package com.sumainfor.wx.system.maket.controller.rentadviser;

import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.system.feign.BaseFeignMarket;
import com.sumainfor.wx.system.feign.BaseFeignZuul;
import com.sumainfor.wx.system.maket.service.RdWorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  租赁顾问
 * <p>
 *
 * @author:zc
 * @create: 2019-08-07 10:19
 **/
@Controller
@RequestMapping("/rdWorder")
public class RdWorderController {

    @Autowired
    RdWorderService rdWorderService;

    @Autowired
    BaseFeignZuul baseFeignZuul;

    @Autowired
    BaseFeignMarket baseFeignMarket;

    /**
     *  今日需带看工单
     * @author zhoucong
     * @data 2019/8/8
     * @ParamgetWorderListToday
     * @return
     */
    @ResponseBody
    @GetMapping("/getWorderListToday")
    public JsonResult getTenantAskListToday(@RequestParam Map<String,Object> params, Pager pager){
        //获取当前登录人的userid
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        System.out.println("OperId================================:"+ContextUtils.getUserId());
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountToday(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getCommunityList=rdWorderService.getWorderListToday(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }


    /**
     * 查询公共转单池
     * @author zhoucong
     * @data 2019/8/8
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getWorderListPublic")
    public JsonResult getWorderListPublic(@RequestParam Map<String,Object> params,Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountPublic(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListPublic(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     *查询私有转单池
     * @param
     * @return
     */
    @ResponseBody
    @GetMapping("/getWorderListPrivate")
    public JsonResult getWorderListPrivate(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){//传入当前登录人的编号
            params.put("TurnSysId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountPrivate(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListPrivate(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }


    /**
     * 创建工单
     * @author zhoucong
     * @data 2019/8/8
     * @Param
     * @return
     */
    @ResponseBody
    @PostMapping("/addWorder")
    public JsonResult addWorder(@RequestBody Map<String,Object> params){
        return baseFeignMarket.addWorder(params);
      //  return rdWorderService.addWorder(params);
    }





    /**
     *
     * 查询服务中心下的全部角色列表，租赁顾问查询转单的伙伴
     */
    @ResponseBody
    @GetMapping("/getWoSaleIdList")
    public JsonResult getWoSaleIdList(@RequestParam Map<String,Object> params){
        //获取当前登录人的服务中心编号
//        SysUserVo userVo = ContextUtils.getSysUser();
//        ParentDeptVo vo = null;
//        for (int i = 0; i < userVo.getLength(); i++) {
//            ParentDeptVo vo1 = userVo.getParentDeptVo();
//            if (vo1.getType().equals(3)) {
//                vo = vo1;
//                break;
//            }
//        }
//        if (vo!=null){
//            params.put("area_id",vo.getDeptId());//当前登录人的服务中心编号
//            System.out.println("area_id:"+vo.getDeptId());
//        }
        params.put("user_id",ContextUtils.getUserId());
        return baseFeignZuul.getWoSaleIdList(params);
    }



    /**
     * 查询所有的服务中心
     * @author zhoucong
     * @data 2019/8/16
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getDeptListByType")
    public JsonResult getDeptListByType(@RequestParam Map<String,Object> params){
        return baseFeignZuul.getDeptListByType(params);
    }



    /**
     *查询租客维护
     * @param
     * @return
     */
    @ResponseBody
    @GetMapping("/getWorderListMaintain")
    public JsonResult getWorderListMaintain(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("SetId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountMaintain(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListMaintain(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }



   /**
    * 点击再次约看
    * @author zhoucong
    * @data 2019/8/27
    * @Param
    * @return
    */
    @ResponseBody
    @PostMapping("/addWorderTenant")
    public JsonResult addWorderTenant(@RequestBody Map<String,Object>params){
        return rdWorderService.addWorderTenant(params);
    }
}
